// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ITask.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the ITask type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Threading
{
    using System;

    public interface ITask : IContinuation, ITaskResult
    {
        /// <summary>
        /// Starts the task.
        /// </summary>
        /// <param name="callBack">The call back.</param>
        /// <param name="userState">State of the user.</param>
        /// <exception cref="InvalidOperationException">Thrown if the task is a continuation task,
        /// or it has already been started.</exception>
        void Start(TaskCallBack callBack, object userState);

        /// <summary>
        /// Continues the task when the specified <see cref="IContinuationSource"/> is marked as completed.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="userState">State of the user.</param>
        /// <exception cref="InvalidOperationException">Thrown if the task is has been started, or
        /// is already a continuation task.</exception>
        void ContinueFrom(IContinuationSource source, TaskCallBack callback, object userState);

        /// <summary>
        /// Gets the <see cref="IContinuationSource"/> for the task.
        /// </summary>
        IContinuationSource ContinuationSource
        {
            get;
        }

        /// <summary>
        /// Gets a value indicating whether the task is complete.
        /// </summary>
        bool IsComplete
        {
            get;
        }

        /// <summary>
        /// Waits for the task to complete
        /// </summary>
        void Wait();
    }

    public interface ITask<T> : ITask, ITaskResult<T>
    {
        void Start(TaskCallBack<T> callBack, object userState);
    }
}